const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors())
const port = 9000

const fs = require('fs')
const morgan = require('morgan')
const writerStream = fs.createWriteStream('./logs/access.log',{
    flags:'a+'
})
// app.use(morgan('combined',{stream:writerStream}))

app.use('/static',express.static('static'))

app.use((req,res,next) => {
    res.cc = (err,status = 1) => {
        res.send({
            status,
            msg:err instanceof Error?err.message:err
        })
    }
    next() 
})


const listRouter = require('./router/tableList')

app.use('/api',listRouter)



app.use((err,req,res,next) => {
    res.cc(err)
})



app.listen(port,() => {
    console.log(`Server running at ${port}`);
})